﻿using System;

using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using GBU.Activities;

namespace GBU
{
    [Activity(Label = "GBU", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : TabActivity
    {
        private RadioGroup radioderGroup;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            TabHost.AddTab(TabHost.NewTabSpec("ONE").SetIndicator("ONE")
            .SetContent(new Intent(this, typeof(SportsActivity))));
            TabHost.AddTab(TabHost.NewTabSpec("TWO").SetIndicator("TWO")
            .SetContent(new Intent(this, typeof(HistoryActivity))));
            TabHost.AddTab(TabHost.NewTabSpec("THREE").SetIndicator("THREE")
            .SetContent(new Intent(this, typeof(AchieveActivity))));
            TabHost.AddTab(TabHost.NewTabSpec("FOUR").SetIndicator("FOUR")
            .SetContent(new Intent(this, typeof(DatingActivity))));
            TabHost.AddTab(TabHost.NewTabSpec("FIVE").SetIndicator("FIVE")
            .SetContent(new Intent(this, typeof(MoreActivity))));

            radioderGroup = (RadioGroup)FindViewById(Resource.Id.main_radio);
            radioderGroup.CheckedChange += radioderGroup_CheckedChange;
            var firstRadio = FindViewById<RadioButton>(Resource.Id.radio_button0);
            firstRadio.Checked = true;

        }

        void radioderGroup_CheckedChange(object sender, RadioGroup.CheckedChangeEventArgs e)
        {
            switch (e.CheckedId)
            {
                case Resource.Id.radio_button0:
                    TabHost.CurrentTab = 0;
                    break;
                case Resource.Id.radio_button1:
                    TabHost.CurrentTab = 1;
                    break;
                case Resource.Id.radio_button2:
                    TabHost.CurrentTab = 2;
                    break;
                case Resource.Id.radio_button3:
                    TabHost.CurrentTab = 3;
                    break;
                case Resource.Id.radio_button4:
                    TabHost.CurrentTab = 4;
                    break;
                default:
                    TabHost.CurrentTab = 0;
                    break;
            }
        }

        private TabHost.TabSpec BuildTab<T>(string tag, string label, int resourcesId) where T : Activity
        {
            var intent = new Intent(this, typeof(T));
            intent.AddFlags(ActivityFlags.NewTask);
            var spec = TabHost.NewTabSpec(tag);
            spec.SetIndicator(label, Resources.GetDrawable(resourcesId));
            spec.SetContent(intent);
            return spec;
        }



        [Activity]
        public class SportsActivity : Activity
        {
            protected override void OnCreate(Bundle savedInstanceState)
            {
                base.OnCreate(savedInstanceState);

                SetContentView(Resource.Layout.Sports);
                var layout = this.FindViewById<RelativeLayout>(Resource.Id.sportshome_btn_newsports);
                layout.Click += new EventHandler(layout_Click);
                //TextView textview = new TextView(this);
                //textview.Text = "This is the History tab";
                //SetContentView(textview);
            }

            void layout_Click(object sender, EventArgs e)
            {
                Intent page = new Intent(this, typeof(CountDownActivity));
                StartActivity(page);
                this.Finish();
            }
        }

        [Activity]
        public class HistoryActivity : Activity
        {
            protected override void OnCreate(Bundle savedInstanceState)
            {
                base.OnCreate(savedInstanceState);

                TextView textview = new TextView(this);
                textview.Text = "This is the History tab";
                SetContentView(textview);
            }
        }

        [Activity]
        public class AchieveActivity : Activity
        {
            protected override void OnCreate(Bundle savedInstanceState)
            {
                base.OnCreate(savedInstanceState);

                TextView textview = new TextView(this);
                textview.Text = "This is the Achieve tab";
                SetContentView(textview);
            }
        }

        [Activity]
        public class DatingActivity : Activity
        {
            protected override void OnCreate(Bundle savedInstanceState)
            {
                base.OnCreate(savedInstanceState);

                TextView textview = new TextView(this);
                textview.Text = "This is the Dating tab";
                SetContentView(textview);
            }
        }

        [Activity]
        public class MoreActivity : Activity
        {
            protected override void OnCreate(Bundle savedInstanceState)
            {
                base.OnCreate(savedInstanceState);

                //TextView textview = new TextView(this);
                //textview.Text = "This is the More tab";
                //SetContentView(textview);
                SetContentView(Resource.Layout.MoreLayout);

                Button btnTakePic = FindViewById<Button>(Resource.Id.btnTakePic);
                btnTakePic.Click += new EventHandler(btnTakePic_Click);

                Button btnShowUser = FindViewById<Button>(Resource.Id.btnShowUser);

                btnShowUser.Click += new EventHandler(btnShowUser_Click);
            }

            void btnShowUser_Click(object sender, EventArgs e)
            {
                StartActivity(new Intent(this,typeof(ShowUserInfoActivity)));
            }

            void btnTakePic_Click(object sender, EventArgs e)
            {
                StartActivity(new Intent(this,typeof(CatchPictureActivity)));
            }
        }
    }
}

